<!--
  The Head
-->

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

  {% if page.layout == 'home' or page.layout == 'post' %}

    {% if site.google_analytics.pv.proxy_endpoint %}
      <meta name="pv-proxy-endpoint" content="{{ site.google_analytics.pv.proxy_endpoint }}">
    {% endif %}

    {% if site.google_analytics.pv.cache_path %}
      <meta name="pv-cache-path" content="{{ site.google_analytics.pv.cache_path | relative_url }}">
    {% endif %}

  {% endif %}

  {% capture seo_tags %}
    {% seo title=false %}
  {% endcapture %}

  {% if site.img_cdn and seo_tags contains 'og:image' %}
    {% assign properties = 'og:image,twitter:image' | split: ',' %}

    {% for prop in properties %}
      {% if site.img_cdn contains '//' %}
        <!-- `site.img_cdn` is a cross-origin URL -->
        {% capture target %}<meta property="{{ prop }}" content="{{ site.url }}{% endcapture %}
        {% capture replacement %}<meta property="{{ prop }}" content="{{ site.img_cdn }}{% endcapture %}
      {% else %}
        <!-- `site.img_cdn` is a local file path -->
        {% capture target %}<meta property="{{ prop }}" content="{{ site.url }}{{ site.baseurl }}{% endcapture %}
        {% assign replacement = target | append: site.img_cdn %}
      {% endif %}

      {% assign seo_tags = seo_tags | replace: target, replacement %}

    {% endfor %}
  {% endif %}

  {{ seo_tags }}

  <title>
  {%- unless page.layout == "home" -%}
    {{ page.title | append: " | "}}
  {%- endunless -%}
    {{ site.title }}
  </title>

  {% include favicons.html %}

  {% if site.resources.ignore_env != jekyll.environment and site.resources.self_hosted %}

    <link href="{{ site.data.assets[origin].webfonts | relative_url }}" rel="stylesheet">

  {% else %}

    {% for cdn in site.data.assets[origin].cdns %}
      <link rel="preconnect" href="{{ cdn.url }}" {{ cdn.args }}>
      <link rel="dns-prefetch" href="{{ cdn.url }}" {{ cdn.args }}>
    {% endfor %}

    <link rel="stylesheet" href="{{ site.data.assets[origin].webfonts | relative_url }}">

  {% endif %}

  <!-- GA -->
  {% if jekyll.environment == 'production'
      and site.google_analytics.id != empty and site.google_analytics.id %}
    <link rel="preconnect" href="https://www.google-analytics.com" crossorigin="use-credentials">
    <link rel="dns-prefetch" href="https://www.google-analytics.com">

    <link rel="preconnect" href="https://www.googletagmanager.com" crossorigin="anonymous">
    <link rel="dns-prefetch" href="https://www.googletagmanager.com">

    {% if site.google_analytics.pv.proxy_endpoint %}
      {% assign proxy_url = site.google_analytics.pv.proxy_endpoint
          | replace: "https://", "" | split: "/" | first | prepend: "https://" %}
      <link rel="preconnect" href="{{ proxy_url }}" crossorigin="use-credentials">
      <link rel="dns-prefetch" href="{{ proxy_url }}">
    {% endif %}
  {% endif %}

  <!-- Bootstrap -->
  <link rel="stylesheet" href="{{ site.data.assets[origin].bootstrap.css | relative_url}}">

  <!-- Font Awesome -->
  <link rel="stylesheet" href="{{ site.data.assets[origin].fontawesome.css | relative_url }}">

  <link rel="stylesheet" href="{{ '/assets/css/style.css' | relative_url }}">

  {% if site.toc and page.toc %}
    <link rel="stylesheet" href="{{ site.data.assets[origin].bootstrap-toc.css | relative_url }}">
  {% endif %}

  {% if page.layout == 'page' or page.layout == 'post' %}
    <!-- Manific Popup -->
    <link rel="stylesheet" href="{{ site.data.assets[origin].magnific-popup.css | relative_url }}">
  {% endif %}

  <!-- JavaScript -->

  <script src="{{ site.data.assets[origin].jquery.js | relative_url }}"></script>

  {% unless site.theme_mode %}
    {% include mode-toggle.html %}
  {% endunless %}
</head>
